<?php
	
	/**
	* @author Robbie Vasquez
 	* @author Matt Kennedy
 	*
	* @param miles
	* @param kilometers
	*/
		
	//creating variables
	$total_miles = 0;
	$total_kilometers = 0;
	
	foreach($info as $r_key => $r_vals)
	{
		$total_miles = $total_miles + $r_vals->miles;
		
		$total_kilometers = $total_kilometers + $r_vals->kilometers;
	}
	
	$total_runs = 0;
	
	foreach($info as $r_key => $r_vals)
	{
		if($r_vals->isDeleted != 1)
			$total_runs = $total_runs + 1;
	}
	
	mysql_connect('2006.ispace.ci.fsu.edu', 'rmv06d', 'zqgvht2m');
	mysql_select_db('runningrecords');
	
	//setting variables equal to 0
	$total_seconds = 0;
	$total_minutes = 0;
	$total_hours = 0;
	
	foreach($info as $r_key => $r_vals)
	{
		$total_seconds = $total_seconds + $r_vals->seconds;
		$total_minutes = $total_minutes + $r_vals->minutes;
		$total_hours = $total_hours + $r_vals->hours;
	}

	if($total_seconds > 59)
	{
		$add_to_minutes = round($total_seconds / 60);
		$total_minutes = round($total_minutes + $add_to_minutes);
		
		$subtract_from_seconds = round($add_to_minutes * 60);
		$total_seconds = $total_seconds - $subtract_from_seconds;
	}

	if($total_minutes > 59)
	{
		$add_to_hours = round($total_minutes / 60);
		$total_hours = round($total_hours + $add_to_hours);
		
		$total_minutes = round($total_minutes - 60 * $add_to_hours);
	}

?>

<!-- requiring header and navigation pages -->
<?php require('includes/header.php'); ?>
<?php require('includes/nav.php'); ?>
	
	<h1>Your Stats:</h1>
	
	<!-- creating table for the statistics -->
	<table class="list">
		<tr>
			<td >Total Runs Recorded:</td>
			<td><?php echo $total_runs; ?></td>
		</tr>
		<tr>
			<td>Total Time Recorded:</td>
			<td><?php echo $total_hours; ?>:<?php echo $total_minutes; ?>:<?php echo $total_seconds; ?></td>
		</tr>
		<tr>
			<td>Total Distance Recorded:</td>
			<td><?php echo $total_miles; ?> Miles / <?php echo $total_kilometers; ?> Kilometers</td>
		</tr>
	</table>
	
<?php require('includes/footer.php'); ?>